package com.ls.readwrite;

import java.util.concurrent.locks.ReentrantReadWriteLock;

//演示读写锁降级
public class Demo1 {
    public static void main(String[] args) {
        //读写锁
        ReentrantReadWriteLock rwLock = new ReentrantReadWriteLock();

        ReentrantReadWriteLock.ReadLock readLock = rwLock.readLock();
        ReentrantReadWriteLock.WriteLock writeLock = rwLock.writeLock();

        //锁降级
        //1获取写锁
        writeLock.lock();
        System.out.println("write");

        //2获取读锁
        readLock.lock();
        System.out.println("read");

        //3释放写锁
        writeLock.unlock();
        //4释放读锁
        readLock.unlock();


    }
}
